package com.focus.xyz.union.cases.frontend;

import com.focus.xyz.core.common.annotation.Task;
import com.focus.xyz.core.common.webdriver.DriverFactory;
import com.focus.xyz.union.action.KeyWordAction;
import com.focus.xyz.core.common.listeners.TC;
import com.focus.xyz.core.utils.ExcelUtils;
import com.focus.xyz.core.utils.ProcessUtil;
import com.focus.xyz.core.utils.prop.ConfigPropInfo;
import com.focus.xyz.union.data.InsDataService;
import com.focus.xyz.union.data.SubAcctBean;
import org.openqa.selenium.WebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.*;

/**
 * Created by chenmeng on 2016/4/18.
 */
public class FrontAllTest extends TC {
    private static transient Logger logger = LoggerFactory.getLogger(FrontAllTest.class);

    private WebDriver driver;
    private KeyWordAction action;
    private ExcelUtils eu;

    @BeforeClass
    public void beforeClass() throws Exception{
        eu = new ExcelUtils(ConfigPropInfo.TEST_DATA_DIR + ConfigPropInfo.TEST_UNION_DATA_FILE);
    }


    @Parameters({"nodeUrl","browser","userName","password"})
    @BeforeMethod(alwaysRun = true)
    public void setUp(String nodeUrl,String browser,String userName,String password) throws Exception {
        driver = DriverFactory.getDriver(nodeUrl).getBrowser(browser);
        super.init(driver);
        action = new KeyWordAction(driver);
        action.LoginFront(userName,password);
    }


    @Parameters({"browser"})
    @AfterMethod(alwaysRun = true)
    public void tearDown(String browser) {
        try{
            super.quit();
            driver.quit();
        }catch (Exception e){
            ProcessUtil.closeBrowser(browser);
        }finally {

        }
    }


    @DataProvider(name = "insData")
    public Object[][] getInsData() throws Exception{
        String[][] data = null;
        try {
            eu.setSelectedSheetName("insData");
            eu.setOnlyReadOneSheet(true);
            eu.setStartReadPos(1);
            eu.setEndReadPos(2);
            data = eu.readExcelArray();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;
    }




    @Test(enabled = false,description = "团体险投保")
    public void TUANTI_TOUBAO() throws Exception{

    }

    /*依赖子账号的创建*/
    @Parameters({"userName"})
//    @Test(dependsOnMethods = {"ADD_SUB"})
    @Test
    public void TOUBAO_SUB(String userName) throws Exception{
        SubAcctBean bean = InsDataService.getSubInfoById("1");
        action.LogoutFront();
        action.LoginFront(userName+"_"+bean.getLoginName(),bean.getLoginPwd());

    }

    /*创建子账号
    * 执行前先执行删除账号脚本
    * */
    @Task(taskName = {"DEL_SUB_ACCT.sql"},paras = {"param1=cimon001_sub001"})
    @Parameters({"userName"})
    @Test(description = "新增子账号校验")
    public void ADD_SUB(String userName) throws Exception{
        SubAcctBean bean = InsDataService.getSubInfoById("1");
        /*用例步骤*/
        action.AddSubAcct(bean,userName,"平安团体意外保险");
    }

    public void SERVICE_FEE() throws Exception{

    }

    @Test
    public void ORDER_CHECK() throws Exception{

    }




    @Test(description = "登出系统")
    public void LOGOUT() throws Exception{
        action.LogoutFront();
    }

}
